#include<iostream>
#include<thread>
#include<mutex>
using namespace std;

//template<class T>
//class Singleton
//{
//public:
//  static T* GetInstance()
//  {
//    return &inst;
//  }
//private:
//  Singleton(const Singleton<T>&)  =delete ;
//  Singleton<T>& operator=(const Singleton<T>&) = delete;
//private:
//  static T inst;
//};
//template<class T>
//T Singleton<T>::inst;
//

template<class T>
class Singleton
{
public:
  static T* GetInstace()
  {
    if(inst == nullptr)
    {
      unique_lock<mutex> uq(_mtx);
      if(inst == nullptr)
      {
        inst = new T();
      }
    }
    return inst;
  }
private:
  Singleton() = default;
  Singleton(const Singleton<T>&)  =delete ;
  Singleton<T>& operator=(const Singleton<T>&) = delete;
private:
  static T* inst;
  static mutex _mtx;
};
template<class T>
T* Singleton<T>::inst;
template<class T>
std::mutex Singleton<T>::_mtx;

int main()
{
  return 0;
}
